package com.awphone.data;

import com.awphone.data.constant.CommentConst;
import com.awphone.data.constant.EObjectType;

import javax.persistence.*;
import java.util.Date;

/**
 * @author a_polyakov
 * Date: 03.03.13
 * Time: 22:35
 * Комментарий
 */
@Entity
@Table(schema = CommentConst.SCHEMA_NAME, name = CommentConst.TABLE_NAME)
public class Comment extends AbstractObject {
    /**
     * Родительский комментарий
     */
    private Comment parentComment;
    /**
     * Телефон
     */
    private Phone phone;
    /**
     * Пользователь создавший комментарий
     */
    private User user;
    /**
     * Текст комментария
     */
    private String text;
    /**
     * Дата создания
     */
    private Date created;
    /**
     * Телефонный номер принадлежит спамеру
     */
    private Boolean phoneBelongsSpammer;
    /**
     * Номер факса
     */
    private Boolean isFax;

    {
        setObjectType(EObjectType.COMMENT);
    }

    public Comment() {
    }

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = CommentConst.S_PARENT_COMMENT, nullable = false, updatable = false)
    public Comment getParentComment() {
        return parentComment;
    }

    public void setParentComment(Comment parentComment) {
        this.parentComment = parentComment;
    }

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = CommentConst.S_PHONE, nullable = false, updatable = false)
    public Phone getPhone() {
        return phone;
    }

    public void setPhone(Phone phone) {
        this.phone = phone;
    }

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = CommentConst.S_USER, nullable = false, updatable = false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = CommentConst.S_TEXT, nullable = false, length = 1024)
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Column(name = CommentConst.S_CREATED, nullable = false, unique = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    @Column(name = CommentConst.S_PHONE_BELONGS_SPAMMER, nullable = false)
    public Boolean getPhoneBelongsSpammer() {
        return phoneBelongsSpammer;
    }

    public void setPhoneBelongsSpammer(Boolean phoneBelongsSpammer) {
        this.phoneBelongsSpammer = phoneBelongsSpammer;
    }

    @Column(name = CommentConst.S_IS_FAX, nullable = false)
    public Boolean getIsFax() {
        return isFax;
    }

    public void setIsFax(Boolean fax) {
        isFax = fax;
    }

    @Override
    public void prePrePersist() {
        super.prePrePersist();
        this.created=new Date();
    }
}
